package com.abc.recycling.mapper;

import com.abc.recycling.model.Address;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface AddressMapper {
    
    @Select("SELECT * FROM address WHERE user_id = #{userId}")
    List<Address> findByUserId(Long userId);
    
    @Select("SELECT * FROM address WHERE id = #{id} AND user_id = #{userId}")
    Address findByIdAndUserId(@Param("id") Long id, @Param("userId") Long userId);
    
    @Insert("INSERT INTO address(user_id, address, contact_name, contact_phone, create_time, update_time) " +
            "VALUES(#{userId}, #{address}, #{contactName}, #{contactPhone}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Address address);
    
    @Update("UPDATE address SET address = #{address}, contact_name = #{contactName}, " +
            "contact_phone = #{contactPhone}, update_time = #{updateTime} WHERE id = #{id} AND user_id = #{userId}")
    int update(Address address);
    
    @Delete("DELETE FROM address WHERE id = #{id} AND user_id = #{userId}")
    int deleteByIdAndUserId(@Param("id") Long id, @Param("userId") Long userId);
} 